package erfgame.core.world.terrain.color;


import erfgame.core.util.ColorUtils;
import erfgame.core.world.terrain.TerrainColorSource;

public class QuickSampledTerrainColorSource implements TerrainColorSource {

	private int[] colors;
	private int[] minColors;
	private int[] maxColors;
	
	private int mask;
	
	public QuickSampledTerrainColorSource( int[] minColors, int[] maxColors, int[] colors, int mask ) {
		this.colors = colors;
		this.minColors = minColors;
		this.maxColors = maxColors;
		this.mask = mask;
	}
	
	public int getColor(int x, int y, int z, int mult, int div, int dCeiling) {
		int sample = ( x*y*z + x+y+z ) & mask;
		int baseColor = this.colors[ sample ];
		int color;
		if( mult > 0 ) {
			int extreme = this.maxColors[ sample ];
			color = ColorUtils.multiplyColor(baseColor, extreme, mult, div );
		} else {
			int extreme = this.minColors[ sample ];
			color = ColorUtils.multiplyColor( baseColor, extreme, -mult, div );
		}
		return color;
	}

}
